<?php
use common\components\widgets\Datetimepicker;

Datetimepicker::widget(['timepicker' => 'true', 'datepicker' => 'false', 'format' => 'H:i', 'step' => '5']);
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height">
    <div class="docs-main">
        <table id="tablesaw" class="tablesaw table yx-table1 yx-table5 table-striped with-check">
            <tr class="yx-bgd2f6ec">
                <td>课程名称</td>
                <td>老师</td>
                <td>上课日期</td>
                <td>上课时间</td>
                <td>课次</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
            <?php foreach ($data as $k => $v) { ?>
                <tr>
                    <input type="hidden" name="lesson_id" value="<?= $v['lesson_id'] ?>">
                    <td><select name="course[]">
                            <option>请选择课程</option>
                            <?php foreach ($course as $kk => $vv) { ?>
                                <?php if ($kk == $v['product_id']) { ?>
                                    <option value="<?= $kk ?>" selected="selected"><?= $vv ?></option>
                                <?php } else { ?>
                                    <option value="<?= $kk ?>"><?= $vv ?></option>
                                <?php } ?>
                            <?php } ?>

                        </select></td>
                    <td><select name="teacher[]">
                            <option>请选择老师</option>
                            <?php foreach ($teacher as $kk => $vv) { ?>
                                <?php if ($kk == $v['teacher_id']) { ?>
                                    <option value="<?= $kk ?>" selected="selected"><?= $vv ?></option>
                                <?php } else { ?>
                                    <option value="<?= $kk ?>"><?= $vv ?></option>
                                <?php } ?>
                            <?php } ?>

                        </select></td>
                    <td><select name="class_date[]">
                            <option>请选择上课日期</option>
                            <?php foreach ($class_date as $kk => $vv) { ?>
                                <?php if ($kk == $v['class_date']) { ?>
                                    <option value="<?= $kk ?>" selected="selected"><?= $vv ?></option>
                                <?php } else { ?>
                                    <option value="<?= $kk ?>"><?= $vv ?></option>
                                <?php } ?>
                            <?php } ?>
                        </select></td>
                    <td><?= \yii\helpers\Html::encode($v['class_time']) ?></td>
                    <td><?= \yii\helpers\Html::encode($v['lesson']) ?></td>
                    <td><?php
                        switch ($v['status']) {
                            case 0:
                                echo '未上课';
                                break;
                            case 1:
                                echo '已上课';
                                break;
                            case 2:
                                echo '教师请假';
                                break;
                            case 3:
                                echo '学生请假';
                                break;
                            case 4:
                                echo '教师停课';
                                break;
                            case 5:
                                echo '代课';
                                break;
                            case 6:
                                echo '复课';
                                break;
                        }
                        ?></td>
                    <td>
                        <?php if ($v['is_overdue'] == 0) { ?>
                            <a href="javascript:;" class="yx-batch-settlement yx-bg7ecef4 yx-ml10 yx-radius2 confirm"
                            >保存</a>
                        <?php } else { ?>
                            <a href="javascript:;" class="yx-batch-settlement yx-bg7ecef4 yx-ml10 yx-radius2"
                               style="background-color: #ccc">已过期</a>
                        <?php } ?>
                    </td>
                </tr>
            <?php } ?>
        </table>
    </div>
</div>
<?php
$js = <<<JS
    $('.confirm').click(function() {
        var tr = $(this).parent().parent();
        var lesson_id = tr.find('input[name="lesson_id"]').val();
        var course = tr.find('select[name="course[]"] option:selected').val();
        var teacher = tr.find('select[name="teacher[]"] option:selected').val();
        var class_date = tr.find('select[name="class_date[]"] option:selected').val();
        $.ajax({
            url:'/artclassmanage-updatelesson',
            data:{
                course : course,
                teacher : teacher,
                class_date : class_date,
                lesson_id : lesson_id
            },
            type : 'post',
            cache : false,
            dataType : 'json',
            success : function(){
                alert('修改成功');
            },
            error : function(){
                alert('修改失败');
            }
        });
    });

    

JS;
$this->registerJS($js);
?>



